namespace BM.Tools.WebControls.MForm.Controls.Tabs
{
    using System;

    using BM.Tools.WebControls.MForm.Controls.Helper;
    using BM.Tools.WebControls.MForm.Controls.Items;

    /// <summary>
    /// The tab that is used for the Root form
    /// </summary>
    public class FormTab : Tab
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FormTab"/> class.
        /// </summary>
        public FormTab()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FormTab"/> class.
        /// </summary>
        /// <param name="targetControl">
        /// The target control.
        /// </param>
        public FormTab(OffspringsOwnerItem targetControl)
        {
            TargetControl = targetControl;
        }

        /// <summary>
        /// Gets OnClickFunction.
        /// </summary>
        /// <value>
        /// The on click function.
        /// </value>
        public override string OnClickFunction
        {
            get
            {
                return null; 
            }
        }

        /// <summary>
        /// Gets or sets TargetControl.
        /// </summary>
        /// <value>
        /// The target control.
        /// </value>
        public new OffspringsOwnerItem TargetControl
        {
            get
            {
                return base.TargetControl as OffspringsOwnerItem;
            }

            set
            {
                base.TargetControl = value;
            }
        }

        /// <summary>
        /// Gets Text.
        /// </summary>
        /// <value>
        /// The text displayed inside the tab.
        /// </value>
        public override string Text
        {
            get
            {
                if (String.IsNullOrEmpty(base.Text))
                {
                    return TargetControl.DisplayName;
                }

                return base.Text;
            }
        }

        /// <summary>
        /// Adds removal button to child controls
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            var button = new RemovalButton(TargetControl)
            {
                OnclickFunction = "BM.TabbedDisplayAddition.remove(this);"
            };
            Controls.Add(button);
        }        
    }
}